package com.example.crowdfundingadminspringboot.service;

import com.example.crowdfundingadminspringboot.mapper.RoleMapper;
import com.example.crowdfundingadminspringboot.pojo.Role;
import com.example.crowdfundingadminspringboot.pojo.RoleExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
	
	@Resource
	RoleMapper roleMapper;
	
	@Override
	public PageInfo<Role> queryForKeywordWithPage(Integer pageNum, Integer pageSize, String keyword) {
		// 1.开启分页功能
		PageHelper.startPage(pageNum, pageSize);
		
		// 2.执行查询
		RoleExample roleExample=new RoleExample();
		RoleExample.Criteria criteria = roleExample.createCriteria();
		criteria.andNameLike("%"+keyword+"%");
		List<Role> list = roleMapper.selectByExample(roleExample);
		// 3.封装为PageInfo对象
		return new PageInfo<>(list);
	}
}

